<!DOCTYPE html>
<html>
<head>
    <title>优惠卡券</title>
<include file="Public/head"/>

	<link href="__CSS__/wxCoupon.css" rel="stylesheet">
	<link href="__CSS__/dataTables.bootstrap.css" rel="stylesheet">
	<link href="__CSS__/custom.css" rel="stylesheet">
	<link href="__CSS__/footable.core.css" rel="stylesheet">
	<link href="__CSS__/datepicker3.css" rel="stylesheet">
<script src="__JS__/bootstrap-datepicker.js"></script>
	<style>
		.ibox-title h5 {
  			margin: 10px 0 0px;
		}
		select.input-sm {
  			height: 35px;
  			line-height: 35px;
		}
		.float-e-margins .btn-info{
			margin-bottom:0px;
		}
		.fa-paste{
			margin-right:7px;
			padding: 0px;
		}
		.dz-preview{
			display:none;
		}
		.ibox-title ul{ list-style: outside none none !important; margin: 0; padding: 0;}
		.ibox-title li { float: left;width: 30%; }
		#commonpage {float: right;margin-bottom: 10px;}
		#table-list-body .btn-st{background-color: #337ab7;border-color: #2e6da4;cursor:auto;}
		#select_Cardtype .i-checks label{cursor: pointer;}
		#ewmPopDiv .modal-body{text-align: center;}
	.modal-footer {text-align: center;}
	.modal-footer .btn {padding: 7px 30px;}
	.js_modify_quantity .fa{margin-left: 10px;}
	#ewmPopDiv .downewm{ font-size: 14px;padding: 15px;text-align: center;}
	.modal-body {padding: 20px 30px 15px;}
	#select_Cardtype p{ margin-bottom: 8px;}
	</style>
	<script src="__JS__/footable.all2.min.js"></script>
</head>

<body>
    <div id="wrapper">
<include file="Public/leftmenu"/>
        <div id="page-wrapper" class="gray-bg">
	     <include file="Public/top"/>
            <div class="row wrapper border-bottom white-bg page-heading">
                <div class="col-lg-10">
                    <h2>优惠卡券</h2>
                    <ol class="breadcrumb">
                        <li>
                            <a>Coupon</a>
                        </li>

                        <li class="active">
                            <strong>Index</strong>
                        </li>
                    </ol>
                </div>
                <div class="col-lg-2">

                </div>
            </div>
        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
            	<div class="col-lg-12">
            	    <div class="ibox float-e-margins">
            	        <div class="ibox-title clearfix">
						<ul class="nav"> 
						<li><button class="btn btn-primary" id="pop_add_card"><i class="fa fa-plus"></i> 创建新卡券 </button></li> 
						</ul> 
            	     </div>
<div class="ibox-content"> 
   <nav class="ui-nav clearfix"> 
    <!--<div class="pull-right common-helps-entry"> 
     <a href="" target="_blank"> <span class="help-icon"></span> 查看【收银台】使用教程 </a> 
    </div>--->
   </nav> 
   <div class="app__content js-app-main page-cashier">
    <div>
      <!-- 实时交易信息展示区dd域 ee--> 
      <div class="cashier-realtime"> 
       <div class="realtime-title-block clearfix"> 
        <h1 class="realtime-title">卡券列表</h1> 
		<form action="" id="search" method="post">
					 <input type="text" style="width:15%;float:left;" value="{$starttime}" name="starttime" class="input-sm form-control" id="ymstart" placeholder="有效开始时间">
																					
					<input type="text"  style="width:15%;float:left;"  value="{$endtime}" name="endtime" class="input-sm form-control" id="ymend" placeholder="有效结束时间">
					<a onclick="return serch();"href="javascript:void(0)" style="" class="btn btn-primary js-create-qrcode">查找</a>
		</form>
       </div> 
      </div> 
      <div class="js-real-time-region realtime-list-box loading">
       <div class="widget-list">
        <div class="js-list-filter-region clearfix ui-box" style="position: relative;">
         <div class="widget-list-filter"></div>
        </div> 
        <div class="ui-box"> 
         <table class="ui-table ui-table-list" data-page-size="20" style="padding: 0px;"> 
          <thead class="js-list-header-region tableFloatingHeaderOriginal">
           <tr class="widget-list-header">
		    <th>编号</th>
            <th>卡券类型</th> 
         
            <th data-hide="phone">卡券有效期</th> 
         <th data-hide="phone">已领取</th>
			<th data-hide="phone">库存</th>
			<th data-hide="phone">操作</th>
           </tr>
          </thead>
          <tbody class="js-list-body-region" id="table-list-body">
																	<notempty name="list">
																	
																		
<volist name="list" id="data">
           <tr class="widget-list-item">
            <td>{$data.id}</td>
			<td><eq name="data.type" value="1">体验券</eq><eq name="data.type" value="2">代金券</eq></td>

			<td>{$data.starttime|date='Y/m/d',###}--{$data.endtime|date='Y/m/d',###}</td> 
          <td>{$data.ling}</td> 
	<!--		<td>
			<eq name="data.status" value="0">正常</eq>
			<eq name="data.status" value="1">已经过期</eq>
			<eq name="data.status" value="0">正常</eq>
			<eq name="data.status" value="0">正常</eq>
			<eq name="data.status" value="0">正常</eq>
			<eq name="data.status" value="0">正常</eq>
			</td>-->
			<td><span>{$data.total}</span><a class="icon_edit js_modify_quantity" href="javascript:;" data-actionid="{$data.id}" data-cdid="{$data.code}"><i class="fa fa-pencil"></i></a></td>
			<td class="footable-visible footable-last-column"> 
			<a class="btn btn-sm btn-white"  href="?s=Coupon/ling&id={$data.id}" style="vertical-align:top;"> 核销记录 </a>  
			<a class="btn btn-sm btn-info"  href="?s=Coupon/add_ticket&type={$data.type}&id={$data.id}" style="vertical-align:top;"> 详 情 </a>  
			<button onclick="deltheOrder(this,{$data.id});" class="btn btn-sm btn-danger"><strong> 删 除 </strong></button></td>
           </tr>
		   </volist>
		    <else/>
		   <tr class="widget-list-item"><td colspan="8">暂无卡券</td></tr>
	       </notempty>
          </tbody> 
         </table> 
         <div class="js-list-empty-region"></div> 
        </div> 
        <div class="js-list-footer-region ui-box">
         <div class="widget-list-footer"></div>
        </div> 
       </div>
      </div> 
     </div>
    </div>
   </div> 
  </div>    
            	</div>
				{$page}
            </div>
        </div>
<include file="Public/footer"/>
        </div>
    </div>

		<div class="modal inmodal" tabindex="-1" role="dialog"  id="Pop_Set_Cardtype">
		<div class="modal-dialog">
			<div class="modal-content animated bounceInRight">
				<div class="modal-header">
                    <button type="button" class="close _close"><span style="font-size: 35px;">×</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">选择卡券类型</h4>
                </div>
				<div class="modal-body">
				<div class="dialog_bd">
					<div class="setting_rows">
					<div class="frm_control_group radio_row">
						<label class="frm_label" for="">选择你要创建的卡券类型</label>
						<div id="select_Cardtype">
							<div class="i-checks">
								<label for="checkbox1">
								<input type="radio"  value="1" id="checkbox1" name="cardtype"> &nbsp;体验券 <i></i>
								</label>
								<p class="frm_tips">可为用户提供免费体验次数</p>
							</div>
							<div class="i-checks">
								<label for="checkbox2">
								<input type="radio"  value="2" id="checkbox2" name="cardtype"> &nbsp;代金券
								<i></i>
								</label>
								<p class="frm_tips">可为用户提供抵扣现金服务。可设置成为“满*元，减*元”</p>
							</div>

						</div>
					</div>
					</div>
					</div>
				</div>
				<div class="modal-footer">
				   <button type="button" class="btn btn-primary btn-confirm">确 定</button>&nbsp;&nbsp;&nbsp;
                   <button type="button" class="btn btn-white _close">取 消</button>
                </div>
			</div>
		</div>
	</div>



<div class="popover" id="quantitypopover">
    <div class="popover_inner">
        <div class="popover_content"><div class="pop_store">
	<!--增减库存-->
	
	<div class="frm_control_group">
        <div class="frm_controls">
			<label class="frm_radio_label selected">
				<input type="radio" class="frm_radio" value="1" checked="" name="isadd">
				<span class="lbl_content">增加</span>
			</label>
			<label class="frm_radio_label">
				<input type="radio" class="frm_radio" value="0" name="isadd">
				<span class="lbl_content">减少</span>
			</label>
		</div>
	</div>
	
	<div class="frm_control_group">                        
		<div class="frm_controls">
			<div class="frm_controls_hint group">
				<span class="frm_input_box"><input type="text" name="quantitynum" class="frm_input js_value" onkeyup="value=value.replace(/[^1234567890]+/g,'')"></span>
				<span class="frm_hint"> 份</span>
			</div>
			<p class="frm_tips fail">库存不能少于1</p>
		</div>
	</div>
	<!--增减库存 end-->
</div></div>
        <div class="popover_bar">
			<button type="button" class="btn btn-primary btn_confirm">确 定</button>&nbsp;&nbsp;&nbsp;
            <button type="button" class="btn btn-white c-close">取 消</button>
        </div>
        
    </div>
    <i class="popover_arrow popover_arrow_out"></i>
    <i class="popover_arrow popover_arrow_in"></i>
</div>

</body>
    <!-- iCheck -->
    <script src="__JS__/icheck.min.js"></script>
 <script>
 		var actid=0,cdid;
		var numObj='';
 $(document).ready(function(){
		$('.ui-table-list').footable();
         $('#select_Cardtype .i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
		  $("#pop_add_card").click(function(){
			   $('body').append('<div class="modal-backdrop in"></div>');
			   $('#Pop_Set_Cardtype').show();
		   });
			$('.realtime-title-block input').datepicker({
                keyboardNavigation: false,
                forceParse: false,
				format: "yyyy-mm-dd",
                autoclose: true
            });

		  $("#Pop_Set_Cardtype ._close").click(function(){
			  $('#Pop_Set_Cardtype').hide();
			  $('.modal-backdrop').remove();
		  });

		 $("#Pop_Set_Cardtype .btn-confirm").click(function(){
			  var typeid=$.trim($('#select_Cardtype input:checked').val());
			  typeid=parseInt(typeid);
			  if(typeid >= 0){
				 window.location.href="?s=Coupon/add_ticket&type="+typeid;
			  }else{
			     alert('请选择一个卡券类型！');
				 return false;
			  }
		  });	



		  $("#ewmPopDiv ._close").click(function(){
			  $('#ewmPopDiv').hide();
			  $('.modal-backdrop').remove();
			  $('#ewmPopDiv .modal-body').html('');
		  });

		/*$('.js_modify_quantity').click(function(){
		   var id=$(this).data('actionid');
		   var cdid=$(this).data('cdid');
		   var offsetpx=$(this).offset();
		   $('#quantitypopover').css('position','absolute').css('left',offsetpx.left-121).css('top',offsetpx.top+7).css('zIndex','100').show();
		});*/
	$(document).on('click',function(e){
		   var target = $(e.target);
		   var quantityobj=target.closest(".js_modify_quantity");
		   if(quantityobj.size()!=0){
		    actid=quantityobj.data('actionid');
		    cdid=quantityobj.data('cdid');
			numObj=quantityobj.siblings('span');
		   var offsetpx=quantityobj.offset();
		   $('#quantitypopover').css('position','absolute').css('left',offsetpx.left-121).css('top',offsetpx.top+7).css('zIndex','100').show();
		   }else if(target.closest("#quantitypopover").size()==0){
			   actid=0;cdid='';numObj='';
		      $("#quantitypopover").hide();
		   }
		});

		$("#quantitypopover .c-close").click(function(){
			  actid=0;cdid='';numObj='';
		     $("#quantitypopover").hide();
		});

		$("#quantitypopover .btn_confirm").click(function(){
			var datas = {id:actid};
			var qtype = $('.frm_control_group input:checked').val();
			var qmun = $('.frm_control_group input[name="quantitynum"]').val();
			qmun=parseInt(qmun);
			var nums = numObj.html();
			 nums = parseInt(nums);
			if(!(qmun > 0)){
			   $('.frm_control_group input[name="quantitynum"]').focus();
			   return false;
			}
			if(qtype==0)
			{
				if(nums<qmun)
				{
					alert('库存不足，无法减少');return false;
				}
		
				numObj.html(nums-qmun);
			}else
			{
                       numObj.html(qmun+nums);
			}
			datas.qtype=qtype;
			datas.qmun=qmun;
		
		    if(cdid){
		     $("#quantitypopover").hide();
				actid=0;cdid='';
				$.ajax({
				url: "?s=Coupon/stock",
				type: "POST",
				dataType: "json",
				data:datas,
				success: function(res){
					if(!res.error){
                      
		
		
				  
						numObj='';
						swal({
							title: "修改成功",
								text: "修改成功",
								type: "success"
							});
					}else{
						swal({
								title: "修改失败",
								text: "修改失败",
								type: "error"
							}, function () {
								//window.location.reload();
							});
					}
				}
				});
			}
		});
	});
/*****删除处理****dd**/
function deltheOrder(dom,id){
   if(confirm('您确定要删除此项？')){
		$.ajax({
			url: "?s=Coupon/del_ticket&id="+id,
			type: "POST",
			dataType: "json",
			data:{id:id},
			success: function(res){
				if(res.error){
					swal({
        				title: "删除成功",
        					text: '',
        					type: "success"
    					}, function () {
        					$(dom).parent().parent('tr').remove();
   						});

				}
			}
		});
   }
}


		function serch(){
		      var ymstart = $("#ymstart").val();
			  var ymend = $("#ymend").val();
 
			  if(ymstart=='' )
			   {
                 	swal({
        					  title: "查找失败",
        					  text: '请填写开始时间',
        					  type: "error"
    						}, function () {
        				
   						   });
						   	return false;
			   }

                $("#search").submit();
		   }
 </script>
 
</html>